package com.glodon.paas.document.dao;

import static org.junit.Assert.*;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.glodon.paas.document.dao.domain.MultiPartUploadHandleEntity;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = { "classpath:test-document-dao.xml", "classpath:paas-document-dao-mysql.xml" })
@Ignore
public class MultiPartUploadHandleDaoMySqlIT {

    String                           defaultRevisionId = "defaultRevisionId";

    @Autowired
    private MultiPartUploadHandleDao multiPartUploadHandleDao;

    @Test
    public void testCRUD() {
        // clear
        int rt = multiPartUploadHandleDao.delete(defaultRevisionId);
        // new
        MultiPartUploadHandleEntity entity = new MultiPartUploadHandleEntity();
        entity.setRevisionId(defaultRevisionId);
        entity.setContentType("contentType");
        entity.setKey("key");
        entity.setManifest("manifest");
        entity.setUploadId("uploadId");

        // insert
        String id = multiPartUploadHandleDao.insert(entity);
        assertEquals(defaultRevisionId, id);

        // get
        entity = multiPartUploadHandleDao.get(defaultRevisionId);
        assertEquals(defaultRevisionId, entity.getRevisionId());

        // getHandlerByRevision
        entity = multiPartUploadHandleDao.getHandlerByRevision(defaultRevisionId);
        assertEquals(defaultRevisionId, entity.getRevisionId());

        // delete
        rt = multiPartUploadHandleDao.delete(defaultRevisionId);
        assertEquals(1, rt);
        entity = multiPartUploadHandleDao.getHandlerByRevision(defaultRevisionId);
        assertNull(entity);
    }
}
